<?php 
//print_r($HttpResult);
if(1==2){$HttpResult = new HttpResult();}
	
	  $HttpContentResult = $HttpResult->getHttpContentResult();
	  //Debug::print_r($HttpResult);
	  //$lang = Config::DEFAULT_LOCALE;
		$head = new HtmlHeader($HttpContentResult->getHeader());
		$head->addCSS('reset');
		$head->addCSS('print','', 'print');
		$head->addCSS('ie',  'css/ie', 'print',true);
		
		$head->addCSS('forum',"css/admin");		
		
		//<!-- PROGRAMACAO JS | JQUERY  -->
		$head->addJS(array('jquery', 'masked'));
		
    //MENU DROPDOWN
    $head->addJS('Menu principal','js/menu/ddsmoothmenu');
    $head->addCSS('Menu CSS','js/menu/ddsmoothmenu');
    
    //TINYMCE
    $head->addJS('tinymce','js/tinymce/jquery.tinymce');
    
    //FILEUPLOAD
    $head->addJS('so','js/uploadify/swfobject');
    $head->addJS('uploadify','js/uploadify/jquery.uploadify.v2.1.4.min');
    $head->addCSS('Upload CSS','js/uploadify/uploadify');
		       
		//SLIDER SHOW
		$head->addJS('cycle', 'js/cycle/jquery.cycle.min');
	
		//<!-- JQUERY UI  -->
		$head->addJS('UI', 'js/UI/js/jquery-ui-1.8.6.custom.min');
		$head->addCSS('UI','js/UI/css/smoothness/jquery-ui-1.8.6.custom');
		
     //SELECTMENU
    $head->addJS('selectmenu','js/UI/development-bundle/ui/jquery.ui.selectmenu');
    $head->addCSS('selectmenu CSS','js/UI/css/jquery.ui.selectmenu');
    
		//<!-- VTIP  -->
		$head->addJS('vtip', 'js/vtip/vtip');
		$head->addCSS('vtip', 'js/vtip/vtip');
		
		//<!-- TABLE SORTER -->
		$head->addJS('tablesorter', 'js/tablesorter/tablesorter');
		$head->addCSS('tablesorter', 'js/tablesorter/tablesorter');
    
    //<!-- PROGRAMACAO JS | JQUERY  -->
    $head->addJS(array('admin','admin_select'));
		
		$header_html = $head->show(TRUE);
$header_html = str_replace(array("democrart", "democrArt", "Democrart", "DemocrArt"), array("expressaoartistica", "Expressão Artística", "Expressão Artística", "Expressão Artística"), $header_html);
echo $header_html;
?>

<body>


<?php include Config::getFolderView("parts/admin/header.php"); 

if(FALSE){
	$this->ContentForumVO = new ContentForumVO();
}
?>

<div id="main">

    <div id="main_content">
    
	    <div class="edit-container-view">
	    		<?php 
	    	//$HttpContentResult->arrayVariable->form_data->fields
	      	function getFieldByName($arrayFields, $field_name){
		      	foreach ( $arrayFields as $field){
		      		if($field->name == $field_name){
		      			return $field;
		      		}
		      	}
	      	}
	      	function getFieldIsVisible($field){
				return ($field->visible == true);
	      	}
	      	?>
	      	<?php
	      	//
	      	$arrayField = $HttpContentResult->arrayVariable->form_data->fields;
	      	
	      	$field = getFieldByName($arrayField, "name"); 
	      	if(getFieldIsVisible($field)){
	      	?>
	        <dl>
	            <dt><?php echo $field->label;?></dt>
	            <dd><?php echo $this->ContentForumVO->getName("pt_BR"); ?></dd>
	        </dl>
	        <?php 
	      	}
	      	$field = getFieldByName($arrayField, "title"); 
	      	if(getFieldIsVisible($field)){
	        ?>
	        <dl>
	            <dt><?php echo $field->label;?></dt>
	            <dd><?php echo $this->ContentForumVO->getTitle("pt_BR"); ?></dd>
	        </dl>
	        <?php 
	      	}
	      	$field = getFieldByName($arrayField, "hat"); 
	      	if(getFieldIsVisible($field)){
	        ?>
	        <dl>
	            <dt><?php echo $field->label;?></dt>
	            <dd><?php echo $this->ContentForumVO->getHat("pt_BR"); ?></dd>
	        </dl>
	        <?php 
	      	}
	      	$field = getFieldByName($arrayField, "description"); 
	      	if(getFieldIsVisible($field)){
	        ?>
	        <dl>
	            <dt><?php echo $field->label;?></dt>
	            <dd>
	            <?php echo $this->ContentForumVO->getDescription("pt_BR"); ?>
	            </dd>
	        </dl>
	   		 <?php 
	      	}
	      	$field = getFieldByName($arrayField, "content"); 
	      	if(getFieldIsVisible($field)){
	        ?>
	         <dl>
	            <dt><?php echo $field->label;?></dt>
	            <dd>
	            <?php echo $this->ContentForumVO->getContent("pt_BR"); ?>
	            </dd>
	        </dl>
			<?php 
	      	}
			?>
	    </div>
    
        
		   <div class="edit-container">
		      
		      <form method="post" name="frmContent" id="frmContent" enctype="multipart/form-data" action="<?php echo $HttpContentResult->arrayVariable->form_data->action; ?>" >
		      	<?php 
		      	
		      	foreach ( $HttpContentResult->arrayVariable->form_data->fields as $field){
		      			//inserindo o que é hidden
						if(isset($field->visible) && $field->visible === FALSE){
							if(isset($field->options) && is_array($field->options)){
								//$field->value deve ser uma array das options
								//se passar value como array ele já gera um array para ser enviado
								foreach($field->selected as $val){
									//enviar um array de valores
									echo "
									<input type='hidden' name='{$field->name}' value='{$val}' />";
								}
							}else{
								echo "
								<input type='hidden' name='{$field->name}' value='{$field->value}' />";	
							}
							continue;
						}
						 
				    	echo '<dl>';
						echo "
						<dt><label for='content_{$field->name}'>{$field->label}</label></dt>"; 
						switch($field->type){
							case "simpleText":
								echo "
								<dd><input type='text' size='60' name='{$field->name}' id='content_{$field->name}' value='{$field->value}' /></dd>";
								break;
								
							case "checkbox":
								$checked = $field->value == 1 ? " checked " : "" ;
								echo "
								<dd><input type='checkbox' $checked name='{$field->name}' id='content_{$field->name}' value='1' /></dd>";
								break;	
							
							case "multiCheckbox":
								// para todo tipo de multi Check vem parar aqui
								echo "
								<dd class='category'>";
								//o nome category é para a classe no CSS apenas
								foreach ($field->options as $option){
									//varre a array e ve se já está selecionado
									$checked = in_array($option->id, $field->selected) ? " checked " : "" ;
									//se nao for passado o campo label pega o campo nome
									$label = (isset($option->label))?$option->label:$option->name;
									echo "
									<div>
											<input {$checked} type='checkbox' $checked name='{$field->name}[]' id='option_{$field->name}_{$option->id}' value='{$option->id}' />
											<label class='multi_check' style='display:inline' for='option_{$field->name}_{$option->id}'>" . $label . "</label>
										 </div>";
								}
								echo "</dd>";
								break;
							case "text":
								echo "<dd><textarea  name='{$field->name}' id='content_{$field->name}' cols='60' rows='12'>{$field->value}</textarea></dd>";
								break; 
								
							case "htmlText":
								echo "<dd><textarea class='tinymce'  name='{$field->name}' id='content_{$field->name}' cols='60' rows='12'>{$field->value}</textarea></dd>";
								break;
						}
						echo '</dl>';
				}
				
				foreach ($HttpContentResult->arrayVariable->form_data->modules as $module=>$formView ){
					if($formView->getQuantity() !== 0){
						include $formView->getFormViewPath();
					}
				}
				//testando 
				
				//se for setado o return_result_vo ele pega a array de messages e exibe, independende se é erro ou sucesso
				if(isset($HttpContentResult->return_result_vo) && count($HttpContentResult->return_result_vo->result) > 0){
			    	foreach($HttpContentResult->return_result_vo->result as $system_message){
			    		$system_message = $formData->translateMessage($system_message);
						?>
						<p class="success"><?php echo $system_message; ?></p>
						<?php
			    	}
			    }
				?>
				    <span class="dotted"></span>
		      	<input class="btn save"  type="submit" value="<?php echo Translation::text('Save') ; ?>" />
		      	
		      </form>
		  
		  </div>
  
    </div>
    
</div>

<?php  include Config::getFolderView("parts/admin/footer.php"); ?>
